<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    document.addEventListener('keydown', function (event) {
      /**
       * event.key      按键的值
       * event.keyCode  按键的值对应的 ASCII 码
       * 
       * 注意事项
       *  ● event.keyCode 在 keydown 和 keyup 中不区分大小写
       *  ● event.keyCode 在 keypress 中区分大小写
       */
      console.log('keydown', event.key, event.keyCode)
    })
    document.addEventListener('keypress', function (event) {
      console.log('keypress', event.key, event.keyCode)
    })
  </script>
</body>

</html>